import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import babel from "@rollup/plugin-babel";
import { terser } from "rollup-plugin-terser";
import postcss from "rollup-plugin-postcss";
import vue from "rollup-plugin-vue";
import replace from "rollup-plugin-replace";
import serve from "rollup-plugin-serve";
import livereload from "rollup-plugin-livereload";

const isProduction = process.env.NODE_ENV === "production";

const plugins = [
  commonjs(),
  resolve(),
  replace({
    "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
  }),
  babel({ babelHelpers: "bundled" }),
  postcss(),
  vue(),
];

if (isProduction) {
  plugins.push(terser());
} else {
  const devPlugin = [
    serve({
      open: true,
      port: 8080,
      contentBase: ".",
    }),
    livereload(),
  ];
  plugins.push(...devPlugin);
}

export default {
  input: "./src/main.js",
  output: {
    format: "umd",
    name: "lycUtils",
    file: "dist/lyc.umd.js",
    globals: {
      lodash: "_",
    },
  },
  external: ["lodash"],
  plugins,
};
